package qc.module.iot.protocol.sl427;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * SL427协议控制域中第4位表示的命令类型码，上行和下行定义相同
 *
 * @author QuCheng Tech
 * @since 2025/11/13
 */
@Getter
@AllArgsConstructor
public enum SL427_FrameControlCommandTypeEnum {
    UN_DEFINE(0x0, "未定义"),//发送/确认
    RAIN(0x1, "雨量"),
    WATER(0x2, "水位"),
    FLOW(0x3, "流量/水量"),
    SPEED(0x4, "流速"),
    GATE(0x5, "闸位"),
    POWER(0x6, "功率"),
    METEOROLOGY(0x7, "气象"),
    ELECTRIC(0x8, "电量"),
    TEMPERATURE(0x9, "水温"),
    QUALITY(0xA, "水质"),
    MOISTURE(0xB, "土壤含水量"),
    EVAPORATION(0xC, "蒸发量"),
    STATUS(0xD, "报警/状态"),
    COMPOSITE(0xE, "综合"),
    PRESSURE(0xF, "水压");

    @EnumValue
    private int index;
    private String name;

    @Override
    public String toString() {
        if (this != null)
            return this.name;

        return null;
    }

    /**
     * 根据int数值获取对应的枚举
     *
     * @param index 数值，限制为1字节，取低4位的值
     * @return qc.module.iot.protocol.sl427.SL427_FrameControlTypeEnum
     * @author QuCheng Tech
     * @since 2025/11/9
     */
    public static SL427_FrameControlCommandTypeEnum getSL427_FrameControlTypeEnum(int index) {
        if (index > 0x0) {
            int byteIntValue = index & 0x0F;//传入的值限制为1字节取低4位的值
            if (byteIntValue > 0x0) {
                for (SL427_FrameControlCommandTypeEnum item : SL427_FrameControlCommandTypeEnum.values()) {
                    if (item.getIndex() == byteIntValue) {//判断序号使用getIndex，判断内容使用getName
                        return item;
                    }
                }
            }
        }
        return SL427_FrameControlCommandTypeEnum.UN_DEFINE;
    }
}
